import json
from apps.pay.recordIncomesLocked.dao import RecordIncomesLockedDao
from dateutil.relativedelta import relativedelta
from decimal import Decimal

def goldCustomHandle(order):
    activityParamsObj = json.loads(order.activityParams)
    print('activityParamsObj', activityParamsObj)
    _order = order
    _user = order.user
    #利率
    rate = activityParamsObj.get('rate')
    #解锁时间
    unlockedTime = (_order.payTime + relativedelta(days=activityParamsObj.get('value'))).strftime('%Y-%m-%d %H:%M:%S')
    # 锁仓金额
    money = _order.realPay.quantize(Decimal("0.00"))
    money2 = (_order.realPay * Decimal(rate)).quantize(Decimal("0.00"))
    # 创建锁仓积分记录
    data = {}
    data['lessee'] = _order.lessee.id
    data['scene'] = 'goldCustom'
    data['user'] = _order.user.id
    data['fromUser'] = _order.user.id
    data['orderId'] = _order.orderId
    data['money'] = money
    data['money2'] = money2
    data['payway'] = ''
    data['changeWay'] = 'add'
    data['unlockedTime'] = unlockedTime
    data['orderStatus'] = 'LOCKED'
    # print('data', data)
    RecordIncomesLockedDao().create(data)